package showtime.framework.ai
{
	import flash.geom.Point;
	
	import showtime.framework.utils.UIDUtility;
	import showtime.framework.manager.supportClasses.cycle.CycleManager;
	import showtime.framework.manager.supportClasses.cycle.ICycleUnit;

	public class AbstractAI implements ICycleUnit
	{
		/**
		 * The character that this AI managers 
		 */		
		protected var handler:AIHandler = null;
		
		protected var intention:String = IntentionType.IDLE;
	
		protected var name:String = null;
		
		protected var interval:int = 1000;
		
		protected var direction:int = 0;
		
		public function getInterval():int
		{
			return interval;
		}
		
		public function getUnitName():String
		{
			return name;
		}
		
		public function execute():void
		{
			switch (intention)
			{
				case IntentionType.ACTIVE:
				{
					onIntentionActive();
					break;
				}
			}
		}
		
		public function AbstractAI(handler:AIHandler)
		{
			this.handler = handler;
			
			name = UIDUtility.createUID();			
			CycleManager.getInstance().addUnit(this);
		}
		
		public function getHandler():AIHandler
		{
			return handler;
		}
		
		public function destroy():void
		{
			CycleManager.getInstance().removeUnit(this);
		}
		
		
		public function setInterval(value:int):void
		{
			interval = value;
		}
		
		public function setDirection(value:int):void
		{
			direction = value;
		}
		
		public function getIntention():String
		{
			return intention;
		}
		
		public function setIntention(intention:String):void
		{
			this.intention = intention;
			
			switch (intention)
			{
				case IntentionType.ACTIVE:
				{
					
					break;
				}
				case IntentionType.ATTACK:
				{					
					break;
				}
				case IntentionType.FOLLOW:
				{
					break;
				}
				case IntentionType.IDLE:
				{
					break;
				}
				case IntentionType.MOVE:
				{
					break;
				}
				case IntentionType.PICK_UP:
				{
					break;
				}
				case IntentionType.REST:
				{
					break;
				}
			}
		}
		
		
		/**
		 * AI functions. 
		 * 
		 */		
		protected function onIntentionIdle():void
		{
			
		}
		
		protected function onIntentionActive():void
		{			
			handler.notify(IntentionType.ACTIVE, int(Math.random() * direction));
		}
		
		protected function onIntentionRest():void
		{
			
		}
		
		protected function onIntenionAattack():void
		{
			
		}
		
		protected function onIntentionMove(destination:Point):void
		{
			
		}
		
		protected function onIntentionPickUp():void
		{
			
		}

	}
}